import { Component } from '@angular/core';
import { DiffViewerComponent } from './diff-viewer/diff-viewer.component';

@Component({
  selector: 'app-root',
  standalone: true,
  imports: [DiffViewerComponent],
  templateUrl: './app.component.html',
  styleUrl: './app.component.css'
})
export class AppComponent {
  title = 'diff-viewer';
  
  // 生成一个XML文件的diff，包含超过5000个差异点
  sampleDiff = this.generateLargeXmlDiff();

  private generateLargeXmlDiff(): string {
    // 生成一个包含超过5000个差异点的XML文件diff
    let diffOutput = `--- a/database_schema.xml\n+++ b/database_schema.xml\n`;
    
    // 生成符合标准unified diff格式的内容
    // 1. 添加文件头差异
    diffOutput += `@@ -1,1 +1,1 @@\n`;
    diffOutput += `-<database>\n`;
    diffOutput += `+<database version="2.0">\n`;
    
    // 2. 添加表格差异（每个表格产生多个差异点）
    // 暂时减少到100个以便测试
    for (let i = 0; i < 100; i++) {
      diffOutput += `@@ -${i*4+3},4 +${i*6+3},6 @@\n`;
      diffOutput += `-  <table name="table${i}">\n`;
      diffOutput += `-    <column name="id${i}" type="int"/>\n`;
      diffOutput += `-    <column name="name${i}" type="varchar"/>\n`;
      diffOutput += `-  </table>\n`;
      diffOutput += `+  <table name="new_table${i}" schema="public">\n`;
      diffOutput += `+    <column name="id${i}" type="bigint" nullable="false"/>\n`;
      diffOutput += `+    <column name="name${i}" type="varchar(255)"/>\n`;
      diffOutput += `+    <column name="created_at${i}" type="timestamp" default="now()"/>\n`;
      diffOutput += `+    <index name="idx_${i}" columns="id${i},name${i}"/>\n`;
      diffOutput += `+  </table>\n`;
    }
    
    // 3. 添加尾部视图差异
    diffOutput += `@@ -20002,2 +30002,6 @@\n`;
    diffOutput += `   </tables>\n`;
    diffOutput += `-</database>\n`;
    diffOutput += `+  <views>\n`;
    diffOutput += `+    <view name="summary_view">\n`;
    diffOutput += `+      <query>SELECT * FROM information_schema.tables</query>\n`;
    diffOutput += `+    </view>\n`;
    diffOutput += `+  </views>\n`;
    diffOutput += `+</database>\n`;
    
    return diffOutput;
  }
}
